home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 1.5 KB | 76 lines | [TEXT/CWIE] |
- // CompileStatistics.cp
-
- #ifndef CompileStatistics_h
- #include "CompileStatistics.h"
- #endif
-
- CompileStatistics::CompileStatistics()
- : lines( 0 ),
- files( 0 ),
- lastLookup( 0 )
- {
- }
-
- CompileStatistics::~CompileStatistics()
- {
- while ( !tree.IsEmpty() )
- {
- FileStatistics *stat = *tree.First();
- delete stat;
- }
- }
-
- uint32 CompileStatistics::AverageLines() const
- {
- return (files == 0) ? 10000 : lines / files;
- }
-
- void CompileStatistics::AddFile( ConstPString name )
- {
- FileStatistics *stat = new FileStatistics( name, AverageLines() );
- files++;
- lines += stat->Lines();
- tree.Add( stat->link );
- lastLookup = stat;
- }
-
- void CompileStatistics::SetFileLines( ConstPString name, uint32 fileLines )
- {
- FileStatistics *stat = Lookup( name );
- Assert( stat != 0 );
-
- lines -= stat->Lines();
- lines += fileLines;
- stat->SetLines( fileLines );
- }
-
- uint32 CompileStatistics::FileLines( ConstPString name ) const
- {
- FileStatistics *stat = Lookup( name );
- return (stat == 0) ? AverageLines() : stat->Lines();
- }
-
- bool CompileStatistics::Known( ConstPString name ) const
- {
- FileStatistics *stat = Lookup( name );
- return stat != 0;
- }
-
- FileStatistics *CompileStatistics::Lookup( ConstPString name ) const
- {
- if ( lastLookup != 0 && lastLookup->Name() == name )
- return lastLookup;
-
- const RedBlackLink<ConstPString,FileStatistics> *node = tree.Find( name );
-
- if ( node == 0 )
- return 0;
-
- const_cast<FileStatistics*&>( lastLookup ) = *node;
-
- Assert( lastLookup->name == name );
- return lastLookup;
- }
-
- #include "RedBlackLinkTree.cp"
-